package projects.jnurse.ioc.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by Adil Naji.
 * User: XP-170708
 * Date: 18 nov. 2008
 * Time: 17:15:25
 */
public class DynamicProxyFactoryImpl implements DynamicProxyFactory {
    @SuppressWarnings("unchecked")
    public <T> T createProxy(Class<T> clazz, T target, AOPInterceptor interceptor) {
        InvocationHandler handler = new DynamicProxyInvocationHandler(target, interceptor);
        return (T) Proxy.newProxyInstance(
                Thread.currentThread().getContextClassLoader(),
                new Class<?>[] {clazz},
                handler
        );

    }
}
